﻿Public Class EditHangVe
    Private bushangve As New BUS.EditHV
    Private dtohangve As New DTO.EditHV
    Private bustracuuhv As New BUS.TraCuuHV
    Private dtotracuuhv As New DTO.TraCuuHV
    Private mahkedit As Integer

    Private Sub clall()
        lbten.Text = ""
        lbghichu.Text = ""
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        dtohangve.tenhv = lbten.Text
        dtohangve.ghichu = lbghichu.Text
        dtohangve.mahv = mahkedit
        If dtohangve.tenhv = "" Then
            MessageBox.Show("Chưa nhập tên hạng vé!", "Lỗi", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error)
            Exit Sub
        End If
        Dim chek As Integer = bushangve.save(dtohangve)
        If chek = Nothing Then
            MessageBox.Show("Không thể sửa. Xin bạn kiểm tra lại ràng buộc từ các bảng dữ liệu khác", "Lỗi", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Stop)
            Exit Sub
        End If
        MessageBox.Show("Thành công!", "Thông báo", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation)
        Me.Hide()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Hide()
    End Sub

    Private Sub HangVe_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.Hide()
        e.Cancel = True
        If Not Main.f_tracuuhv Is Nothing Then
            Main.f_tracuuhv.dghangve.DataSource = bustracuuhv.dtload().Tables(0)
        End If
    End Sub

    Private Sub loaddt(ByVal mahkedit As Integer)
        Me.mahkedit = Val(Label5.Text)
        Dim dshk As DataSet = bushangve.dtload(Me.mahkedit)
        lbten.Text = dshk.Tables(0).Rows(0).Item(1).ToString
        lbghichu.Text = dshk.Tables(0).Rows(0).Item(2).ToString
    End Sub

    Private Sub EditHangVe_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        loaddt(mahkedit)
    End Sub
End Class